package com.ceshiren.springstudy.dao.impl;

import com.ceshiren.springstudy.dao.UserDao;
import com.ceshiren.springstudy.dto.TestUser;
import org.apache.commons.codec.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.List;

@Component
public class UserDaoImpl implements UserDao {

    @Override
    public List<TestUser> findAll() {
        InputStream inputStream = Resources.getInputStream("SqlMapConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sessionFactory.openSession();
        List<TestUser> testUserList = session.selectList("user1.findAll");
        session.close();
        return testUserList;
    }
}
